package com.webtest.fileupload;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/8/22 20:05
 */
public class FileUploadAppListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("upload.properties")){
            Properties properties = new Properties();
            properties.load(inputStream);
            for (Map.Entry<Object, Object> objectObjectEntry : properties.entrySet()) {
                String propertyName = objectObjectEntry.getKey().toString();
                String propertyValue = objectObjectEntry.getValue().toString();
                FileUploadAppProperties.getInstance().addProperty(propertyName, propertyValue);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
